package ninth.线程操作案例.问题解决1_加入同步;

class Info {
    private String name;
    private String content;

    public synchronized void set(String name, String content) {
        this.setName(name);
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        this.setContent(content);
    }

    public synchronized void get() {
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(this.getName() + " --> " + this.getContent());
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}

public class 修改Info类 {
    public static void main(String[] args) {
        Info info = new Info();
        Producer1 pro = new Producer1(info);
        Consumer1 con = new Consumer1(info);
        new Thread(pro).start();
        new Thread(con).start();
    }
}
